package com.hello.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hello.common.log.annotation.Log;
import com.hello.common.log.enums.BusinessType;
import com.hello.common.security.annotation.RequiresPermissions;
import com.hello.system.domain.FriendRequests;
import com.hello.system.service.IFriendRequestsService;
import com.hello.common.core.web.controller.BaseController;
import com.hello.common.core.web.domain.AjaxResult;
import com.hello.common.core.utils.poi.ExcelUtil;
import com.hello.common.core.web.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 好友申请请求Controller
 * 
 * @author hello
 * @date 2025-10-29
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/friendRequests")
public class FriendRequestsController extends BaseController
{
    private final IFriendRequestsService friendRequestsService;

    /**
     * 查询好友申请请求列表
     */
    @RequiresPermissions("system:friendRequests:list")
    @GetMapping("/list")
    public TableDataInfo list(FriendRequests friendRequests)
    {
        startPage();
        List<FriendRequests> list = friendRequestsService.selectFriendRequestsList(friendRequests);
        return getDataTable(list);
    }

    /**
     * 导出好友申请请求列表
     */
    @RequiresPermissions("system:friendRequests:export")
    @Log(title = "好友申请请求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FriendRequests friendRequests)
    {
        List<FriendRequests> list = friendRequestsService.selectFriendRequestsList(friendRequests);
        ExcelUtil<FriendRequests> util = new ExcelUtil<FriendRequests>(FriendRequests.class);
        util.exportExcel(response, list, "好友申请请求数据");
    }

    /**
     * 获取好友申请请求详细信息
     */
    @RequiresPermissions("system:friendRequests:query")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
        return success(friendRequestsService.selectFriendRequestsByRequestId(requestId));
    }

    /**
     * 新增好友申请请求
     */
    @RequiresPermissions("system:friendRequests:add")
    @Log(title = "好友申请请求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FriendRequests friendRequests)
    {
        return toAjax(friendRequestsService.insertFriendRequests(friendRequests));
    }

    /**
     * 修改好友申请请求
     */
    @RequiresPermissions("system:friendRequests:edit")
    @Log(title = "好友申请请求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FriendRequests friendRequests)
    {
        return toAjax(friendRequestsService.updateFriendRequests(friendRequests));
    }

    /**
     * 删除好友申请请求
     */
    @RequiresPermissions("system:friendRequests:remove")
    @Log(title = "好友申请请求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(friendRequestsService.deleteFriendRequestsByRequestIds(requestIds));
    }
}
